class Categories < Application
  provides :xml, :js, :yaml
  
  def index
    @categories = Category.find(:all)
    render @categories
  end
  
  def show
    @category = Category.find(params[:id])
    render @category
  end
  
  def new
    only_provides :html
    @category = Category.new(params[:category])
    render
  end
  
  def create
    @category = Category.new(params[:category])
    @category.user_id = current_user.id
    if @category.save
      redirect url(:category, @category)
    else
      render :action => :new
    end
  end
  
  def edit
    only_provides :html
    @category = Category.find(params[:id])
    render
  end
  
  def update
    @category = Category.find(params[:id])
    if @category.update_attributes(params[:category])
      redirect url(:category, @category)
    else
      raise BadRequest
    end
  end
  
  def destroy
    @category = Category.find(params[:id])
    if @category.destroy
      redirect url(:categorys)
    else
      raise BadRequest
    end
  end
end